package com.geekaca.chat;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class ServerChat {
    // key: 客户端socket
    // value: 客户端昵称
    public static Map<Socket, String> onLineSocketMap = new HashMap<>();

    public static StringBuilder names = new StringBuilder();

    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(ChatConstants.PORT);) {
            System.out.println("ServerSocket 启动 port: " + ChatConstants.PORT);
            while (true) {
                Socket clientSocket = serverSocket.accept();
                ServerRunnable serverRunnable = new ServerRunnable(clientSocket);
                new Thread(serverRunnable).start();
            }
        } catch (IOException e) {
            System.out.println(" 发生异常 " + e.getMessage());
            e.printStackTrace();
        }
    }
}
